/**
 * 集合框架常用的几个类
 */
package edu.gzz;

import java.util.Vector;
import java.util.ArrayList;
import java.util.HashMap;

/**
 * @author gzz
 *
 */
public class CollectionTest {

	// ArrayList的用法
	public static void main(String args[]) {

		// ArrayList
		ArrayList<Integer> b = new ArrayList<>();
		b.add(1);
		b.add(3);
		b.add(5);

		// change
		b.set(1, 2);

		// put elements of b
		System.out.println("Element of b:");
		b.forEach(x -> {
			System.out.println(x);
		});

		for (Integer x : b) {
			System.out.println(x);
		}

		// HashMap
		HashMap<Integer, String> hmp = new HashMap<Integer, String>();
		hmp.put(1, "hello");
	}

	// Vector的用法
	public static void VectorTest() {
		// Vector
		Vector<String> a = new Vector<String>();

		a.addElement("hello");
		a.addElement("java");
		a.addElement("world");

		System.out.println("element num=" + a.size());
		System.out.println("capacity=" + a.capacity());
		System.out.println(a.toString());

		for (int i = 0; i < a.size(); i++) {
			System.out.println(a.elementAt(i));
		}
	}
}
